{include file="public/com_header"}

<body style="padding:10px;">
    <div class="tplay-body-div">
    <div class="layui-tab">
      <ul class="layui-tab-title">
        <li class="layui-this">文章管理</li>
        <li><a href="{:url('admin/article/publish')}" class="a_menu">新增文章</a></li>
      </ul>
    </div> 
      <form class="layui-form serch" action="{:url('admin/article/index')}" method="post">
        <div class="layui-form-item" style="float: left;">
          <div class="layui-input-inline">
            <input type="text" name="keywords" lay-verify="title" autocomplete="off" placeholder="请输入关键词" class="layui-input layui-btn-sm">
          </div>
          <div class="layui-input-inline">
            <div class="layui-inline">
                <select name="article_cate_id" lay-search="">
                  <option value="">分类</option>
                  {volist name="$info.cate" id="vo"}
                  <option value="{$vo.id}">{$vo.name}</option>
                  {/volist}
                </select>
            </div>
          </div>
          <div class="layui-input-inline">
            <div class="layui-inline">
                <select name="status" lay-search="">
                  <option value="">状态</option>
                  <option value="0">待审核</option>
                  <option value="1">已审核</option>
                </select>
            </div>
          </div>
          <div class="layui-input-inline">
            <div class="layui-inline">
                <select name="is_top" lay-search="">
                  <option value="">置顶</option>
                  <option value="0">未置顶</option>
                  <option value="1">已置顶</option>
                </select>
            </div>
          </div>
          <div class="layui-input-inline">
            <div class="layui-inline">
                <select name="admin_id" lay-search="">
                  <option value="">创建人</option>
                  {volist name="$info.admin" id="vo"}
                  <option value="{$vo.id}">{$vo.nickname}</option>
                  {/volist}
                </select>
            </div>
          </div>
          <div class="layui-input-inline">
            <div class="layui-inline">
              <div class="layui-input-inline">
                <input type="text" class="layui-input" id="create_time" placeholder="创建时间" name="create_time">
              </div>
            </div>
          </div>
          <button class="layui-btn layui-btn-danger layui-btn-sm" lay-submit="" lay-filter="serch">立即提交</button>
        </div>
      </form> 
    <table class="layui-table" lay-size="sm">
      <colgroup>
        <col width="50">
        <col width="300">
        <col width="50">
        <col width="100">
        <col width="100">
        <col width="150">
        <col width="100">
        <col width="150">
        <col width="50">
        <col width="50">
        <col width="100">
      </colgroup>
      <thead>
        <tr>
          <th>ID</th>
          <th>标题</th>
          <th>缩略图</th>
          <th>分类</th>
          <th>创建人</th>
          <th>创建时间</th>
          <th>最后修改人</th>
          <th>最后修改时间</th>
          <th>置顶</th>
          <th>审核</th>
          <th>操作</th>
        </tr> 
      </thead>
      <tbody>
        {volist name="articles" id="vo"}
        <tr>
          <td>{$vo.id}</td>
          <td>{$vo.title}</td>
          <td><a href="{$vo.thumb|geturl}" class="tooltip"><img src="{$vo.thumb|geturl}" width="20" height="20"></a></td>
          <td>{$vo.cate.name}</td>
          <td>{$vo.admin.nickname}</td>
          <td>{$vo.create_time}</td>
          <td>{$vo.edit_admin}</td>
          <td>{$vo.update_time}</td>
          <td><a href="javascript:;" style="font-size:18px;" class="is_top" data-id="{$vo.id}" data-val="{$vo.is_top}">{eq name="vo.is_top" value="1"}<i class="fa fa-toggle-on"></i>{else /}<i class="fa fa-toggle-off"></i>{/eq}</a></td>
          <td><a href="javascript:;" style="font-size:18px;" class="status" data-id="{$vo.id}" data-val="{$vo.status}">{eq name="vo.status" value="1"}<i class="fa fa-toggle-on"></i>{else /}<i class="fa fa-toggle-off"></i>{/eq}</a></td>
          <td class="operation-menu">
            <div class="layui-btn-group">
              <a href="{:url('admin/article/publish',['id'=>$vo.id])}" class="layui-btn layui-btn-xs a_menu layui-btn-primary" style="margin-right: 0;font-size:12px;"><i class="layui-icon"></i></a>
              <a href="javascript:;" class="layui-btn layui-btn-xs layui-btn-primary delete" id="{$vo.id}" style="margin-right: 0;font-size:12px;"><i class="layui-icon"></i></a>
            </div>
          </td>
        </tr>
        {/volist}
      </tbody>
    </table>
    <div style="padding:0 20px;">{$articles->render()}</div> 
    {include file="public/foot"}
    <script type="text/javascript">

    $('.delete').click(function(){
      var id = $(this).attr('id');
      layer.confirm('确定要删除?', function(index) {
        $.ajax({
          url:"{:url('admin/article/delete')}",
          data:{id:id},
          success:function(res) {
            layer.msg(res.msg);
            if(res.code == 1) {
              setTimeout(function(){
                location.href = res.url;
              },1500)
            }
          }
        })
      })
    })
    </script>
    <script type="text/javascript">

    $('.is_top').click(function(){
      var val = $(this).attr('data-val');
      var id = $(this).attr('data-id');
      var i = $(this).find('i');
      var the = $(this);
      if(val == 1){
        var is_top = 0;
      } else {
        var is_top = 1;
      }
      $.ajax({
        type:"post",
        url:"{:url('admin/article/is_top')}",
        data:{is_top:is_top,id:id},
        success:function(res){
          
          if(res.code == 1) {
            top();
          } else {
            layer.msg(res.msg);
          }
        }
      })

      function top(){
        if(val == 1){
          i.attr("class","fa fa-toggle-off");
          the.attr('data-val',0);
        } else {
          i.attr("class","fa fa-toggle-on");
          the.attr('data-val',1);
        }
      }
    })


    $('.status').click(function(){
      var val = $(this).attr('data-val');
      var id = $(this).attr('data-id');
      var i = $(this).find('i');
      var the = $(this);
      if(val == 1){
        var status = 0;
      } else {
        var status = 1;
      }
      $.ajax({
        type:"post",
        url:"{:url('admin/article/status')}",
        data:{status:status,id:id},
        success:function(res){
          
          if(res.code == 1) {
            tostatus();
          } else {
            layer.msg(res.msg);
          }
        }
      })

      function tostatus(){
        if(val == 1){
          i.attr("class","fa fa-toggle-off");
          the.attr('data-val',0);
        } else {
          i.attr("class","fa fa-toggle-on");
          the.attr('data-val',1);
        }
      }
    })
    </script>
  </div>
</body>
</html>
